<template>
  <div id="maincom">
    <el-table
      ref="multipleTable"
      :data="viparr"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="id" label="序号" width="50"></el-table-column>
      <el-table-column prop="card" label="卡号" width="100"> </el-table-column>
      <el-table-column prop="type" label="会员类型"> </el-table-column>
      <el-table-column prop="grade" label="会员等级">
        <template slot-scope="scope">
          <span
            v-text="scope.row.grade"
            style="
              color: #ffeabb;
              font-style: oblique;
              font-weight: bold;
              font-size: 18px;
            "
          ></span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="会员姓名"> </el-table-column>
      <el-table-column prop="phone" label="手机号码" width="100">
      </el-table-column>
      <el-table-column prop="consumption" label="累计消费(元)">
      </el-table-column>
      <el-table-column prop="rest" label="储存余额(元)"> </el-table-column>
      <el-table-column prop="store" label="累计储值(元)"> </el-table-column>
      <el-table-column prop="score" label="积分"> </el-table-column>
      <el-table-column prop="startTime" label="开卡时间"> </el-table-column>
      <el-table-column prop="ddl" label="到期时间">
        <template slot-scope="scope">
          <span
            v-text="
              +scope.row.startTime.split('-')[0] +
              1 +
              '-' +
              scope.row.startTime.split('-')[1] +
              '-' +
              scope.row.startTime.split('-')[2]
            "
          ></span>
        </template>
      </el-table-column>
      <el-table-column prop="state" label="会员状态">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.state"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column prop="operation" label="操作">
        <template slot-scope="scope">
          <span
            style="color: #bbb; cursor: pointer"
            @click="scope.row.isShow = !scope.row.isShow"
            >操作</span
          >
          <div v-show="scope.row.isShow">
            <el-button type="warning" plain @click="editrow([scope.row.id,scope.row.name,scope.row.card,scope.row.phone,scope.row.type,scope.row.startTime])">编辑</el-button>
            <el-button type="danger" plain @click="delsingle(scope.row.id)"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { delVIP, delbatchVIP } from "../../../api/VIP";
import Bus from "../../../utils/BUS";
export default {
  props: ["viparr"],
  mounted() {
    Bus.$on("batchDel", this.mainbatchdel); //绑定事件
  },
  beforeDestroy() {
    Bus.$off("batchDel", this.mainbatchdel); //解绑
  },
  data() {
    return {
      count: 0,
      opebool: "",
      multipleSelection: [],
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delsingle(id) {
      delVIP({ id: id }).then((res) => {
        if (res.code == 200) {
          this.$emit("resetparentfun");
        }
      });
    },
    mainbatchdel() {
      //批量删除
      let ids = "";
      console.log(this.multipleSelection);
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach((item) => {
          ids += item.id + ",";
        });
        ids = ids.slice(0, ids.length - 1);
      }
      console.log(ids);
      delbatchVIP({ ids: ids }).then((res) => {
        if (res.code == 200) {
          this.$emit("resetparentfun");
        }
      });
    },
    editrow(arr){
      console.log(arr);
      Bus.$emit("openEditDialog",arr)
      // console.log(row);
    }
  },
};
</script>

<style>
.el-table .el-table__cell {
  text-align: center !important;
}
.el-button + .el-button {
  margin-left: 0px !important;
}
.el-table th.el-table__cell > .cell {
  cursor: pointer;
}
</style>
